<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        
        class Iphone {
            constructor() {}
            call() {
                console.log('Phones from the iPhone');
            }
        }

        class HuaWei {
            constructor() {}
            call() {
                console.log('Phones from the HuaWei')
            }
        }

        class Google {
            constructor() {}
            call() {
                console.log('Phones from the Google')
            }
        }

        // 工厂模式，创建
        class DatabaseConnectFactory {
            constructor() {}
            getDbConnect(dbType) {
                let objKeys = ['Iphone', 'HuaWei', 'Google'];
                let objMap = new Map();
                objMap.set(objKeys[0], Iphone);
                objMap.set(objKeys[1], HuaWei);
                objMap.set(objKeys[2], Google);
                if (objKeys.includes(dbType)) {
                    return new (objMap.get(dbType))();
                }
                return {}
            }
        }

        const dbConnectFactory = new DatabaseConnectFactory();

        // 根据工厂类，生产各种对象
        let iphone = dbConnectFactory.getDbConnect('Iphone');
        let huaWei = dbConnectFactory.getDbConnect('HuaWei');
        let google = dbConnectFactory.getDbConnect('Google');
        let otherPhone = dbConnectFactory.getDbConnect('otherPhone');

        iphone.call(); // Phones from the iPhone
        huaWei.call(); // Phones from the HuaWei
        google.call(); // Phones from the Google
        otherPhone.call(); // 报错， Uncaught TypeError: otherPhone.call is not a function

    </script>
</body>
</html>